<?php
class FConfirmAction extends CommonAction {

    public function index()
    {
        $foreign = M('Foreign');
        $foreignCount = M('Foreign_count');

        $foreignData = $foreign->select();
        $this->assign('foreignData', $foreignData);

        if(isset($_POST['send']))
        {
            $type = $this->_post('type');
            $date =  date('Y-m-d');

            $map['date'] = $date;
            $map['type'] = $type;
            $foreignCount->where($map)->find();
            if($foreignCount->where($map)->find())
            {
                $foreignCount->where($map)->setInc('number', 1);
                redirectByModal('确认成功!', self::$SUCCESS, __URL__.'/index');
                return ;
            }

            $data['type'] = $type;
            $data['number'] = 1;
            $data['date'] = $date;

            if($foreignCount->add($data))
                redirectByModal('确认成功!', self::$SUCCESS, __URL__.'/index');
        }

        $this->display();
    }
}